<?php

namespace App\Console\Commands;

use App\Datas\ModelList;
use Illuminate\Console\Command;

use App\Tools\File;

class ImportModelCommand extends BaseCommand
{
    /**
     * 命令行执行命令
     * @var string
     */
    protected $signature = 'importModel';

    /**
     * 命令描述
     *
     * @var string
     */
    protected $description = 'import model list';

    public function handle() {
        $file = $this->rootPath."/tmp/model_list.txt";
        $list = File::getFileLines($file,1,25);
        array_walk($list,function (&$value) {
            $value = mb_convert_encoding(trim($value),"UTF-8","GBK");
            $value = explode("\t",$value);
        });
        $data = [];
        foreach ($list as $item) {
            $data[] = [
                "name" => $item[4],
                "model" => str_replace(".safetensors","",$item[3]),
                "negative_prompt" => trim($item[5],"\""),
                "img2img" => $item[6]
            ];
        }
        ModelList::getInstance()->insert($data);
    }
}